package com.cuijq.virwallet.service.bo;

import com.cuijq.virwallet.exception.InsufficientBalanceException;
import com.cuijq.virwallet.exception.InvalidAmountException;

import java.math.BigDecimal;

public class VirtualWallet {
    private Long id;
    private Long createTime = System.currentTimeMillis();
    private BigDecimal balance = BigDecimal.ZERO;

    public VirtualWallet(){

    }
    public VirtualWallet(Long preAllocatedId) {
        this.id = preAllocatedId;
    }

    public BigDecimal balance() {
        return this.balance;
    }

    public void debit(BigDecimal amount) {
        if (this.balance.compareTo(amount) < 0) {
            try {
                throw new InsufficientBalanceException("");
            } catch (InsufficientBalanceException e) {
                e.printStackTrace();
            }
        } this.balance = this.balance.subtract(amount);
    }

    public void credit(BigDecimal amount) {
        if (amount.compareTo(BigDecimal.ZERO) < 0) {
            try {
                throw new InvalidAmountException("...");
            } catch (InvalidAmountException e) {
            }
        } this.balance = this.balance.add(amount);
    }

}
